function PageHelper() {

}

/**
 * 页面初始化
 * @param {Object} option 配置项
 */
PageHelper.prototype.init = function(option) {
	//字典加载
	new DicManager().init();
}

/**
 * 重写alert函数
 */
PageHelper.prototype.rewriteAlert = function() {
	if (typeof mini != "undefined") {
		window.browserAlert = window.alert;
		window.alert = function(msg) {
			mini.alert(msg);
		};
	}
}

/**
 * 全局ajax设置
 */
PageHelper.prototype.globalAjaxSetting = function() {
	$.ajaxSetup( {
		cache : false,
		beforeSend : function(jqXHR, settings) {
			$(document).data("lastAjaxSettings", null);
		},
		complete : function(jqXHR, status) {
			var settings = $(document).data("lastAjaxSettings");
			$(document).data("lastAjaxSettings", null);
			if (jqXHR.responseText.match("^\{(.+:.+,*){1,}\}$")) {
				if (status == "success") {
					var response = $.parseJSON(jqXHR.responseText);
					if (response && !response.success) {
						if (response.msg) {
							alert(response.msg);
						}
						if (response.type == "logon") {
							top.location.href = serverPath
									+ "/system/toLogon.do";
						}
					}
				} else {
					alert("系统异常");
				}
			}
		}
	});
}

/**
 * 防止console.log错误
 */
PageHelper.prototype.preventConsoleLogErrors = function() {
	if (!window.console) {
		window.console = {};
	}
	var m = [ "log", "info", "warn", "error", "debug", "trace", "dir", "group",
			"groupCollapsed", "groupEnd", "time", "timeEnd", "profile",
			"profileEnd", "dirxml", "assert", "count", "markTimeline",
			"timeStamp", "clear" ];
	for ( var i = 0; i < m.length; i++) {
		if (!window.console[m[i]]) {
			window.console[m[i]] = function() {
			};
		}
	}
}

/**
 * 全局错误处理
 * @param {Object} e 响应对象
 */
PageHelper.prototype.commonError = function(e) {
	var result = e.result;
	if (result && !result.success) {
		if (result.msg) {
			alert(result.msg);
		}
		if (result.type == "logon") {
			top.location.href = serverPath + "/auth/user/toLogon.do";
		}
	}
}

/**
 * 扩充校验规则
 */
PageHelper.prototype.extendValidationRules = function() {
	if (typeof mini != "undefined") {
		mini.VTypes["cellphoneErrorText"] = "请输入手机号格式";
		mini.VTypes["cellphone"] = function(v) {
			return ValidateUtil.prototype.isCellphone(v);
		}
		mini.VTypes["telephoneErrorText"] = "请输入固定电话格式";
		mini.VTypes["telephone"] = function(v) {
			return ValidateUtil.prototype.isTelephone(v);
		}
		mini.VTypes["chineseErrorText"] = "请输入中文格式";
		mini.VTypes["chinese"] = function(v) {
			return ValidateUtil.prototype.isChinese(v);
		}
		mini.VTypes["letterAndNumberErrorText"] = "请输入字母、数字或下划线格式";
		mini.VTypes["letterAndNumber"] = function(v) {
			return ValidateUtil.prototype.isLetterAndNumber(v);
		}
		mini.VTypes["organCodeErrorText"] = "请输入组织机构代码格式";
		mini.VTypes["organCode"] = function(v) {
			return ValidateUtil.prototype.isOrganCode(v);
		}
		mini.VTypes["socialCreditErrorText"] = "请输入社会信用代码格式";
		mini.VTypes["socialCredit"] = function(v) {
			return ValidateUtil.prototype.isSocialCredit(v);
		}
		mini.VTypes["idCardErrorText"] = "请输入身份证号格式";
		mini.VTypes["idCard"] = function(v) {
			return ValidateUtil.prototype.isIdCard(v);
		}
	}
}